package com.bainarm.library_fragment;

import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.MediaController;
import android.widget.VideoView;
import androidx.fragment.app.Fragment;

public class VideoFragment extends Fragment {

    private VideoView videoView;

    public VideoFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_video, container, false);
        videoView = view.findViewById(R.id.videoView);

        // 设置视频路径
        String videoUrl = "http://www.w3school.com.cn/i/movie.mp4"; // 替换为实际视频的 URL
        Uri videoUri = Uri.parse(videoUrl);
        videoView.setVideoURI(videoUri);

        // 为视频绑定媒体控制器
        MediaController mediaController = new MediaController(getActivity());
        videoView.setMediaController(mediaController);
        mediaController.setAnchorView(videoView);

        // 开始播放视频
        videoView.start();

        return view;
    }

}
